define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'hf/qdgoods/index' + location.search,
                    add_url: 'hf/qdgoods/add',
                    edit_url: 'hf/qdgoods/edit',
                    del_url: 'hf/qdgoods/del',
                    multi_url: 'hf/qdgoods/multi',
                    import_url: 'hf/qdgoods/import',
                    table: 'hf_goods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                showToggle: false, // 浏览模式切换
                showColumns: true, // 允许选择显示字段
                showExport: true, // 导出选项
                exportDataType: "basic", //导出当前页
                exportTypes: ['excel'],
                searchFormVisible: false, // 通用搜索 默认是否显示
                search: false, // 是否关闭搜索
                trimOnSearch: true, // 自动删除搜索空格
                pageList: [10, 20, 30, 50],
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [{
                            checkbox: true
                        },
                        {
                            field: 'id',
                            title: __('Id')
                        },
                        {
                            field: 'mz',
                            title: __('Mz')
                        },
                        {
                            field: 'title',
                            title: __('Title'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'price',
                            title: __('Price'),
                            operate: false
                        },
                        {
                            field: 'price_h5',
                            title: __('h5价格'),
                            operate: false
                        },
                        {
                            field: 'type',
                            title: __('Type'),
                            searchList: {
                                "1": __('Type 1'),
                                "2": __('Type 2')
                            },
                            formatter: Table.api.formatter.normal
                        },
                        {
                            field: 'yys',
                            title: __('Yys'),
                            searchList: {
                                "1": __('Yys 1'),
                                "2": __('Yys 2'),
                                "3": __('Yys 3')
                            },
                            formatter: Table.api.formatter.normal
                        },
                        {
                            field: 'statuss',
                            title: __('Statuss'),
                            searchList: {
                                "1": __('Statuss 1'),
                                "2": __('Statuss 2')
                            },
                            formatter: Table.api.formatter.normal
                        },
                        {
                            field: 'forbid',
                            title: __('Forbid'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [{
                                name: 'view',
                                text: '提交订单',
                                title: '提交订单',
                                classname: 'btn btn-xs btn-success btn-dialog',
                                icon: 'fa fa-circle-o',
                                url: 'hf/qdgoods/sub?ids={ids}',
                                //refresh: true,
                                callback: function (data) {
                                    Fast.api.close(data);
                                }
                            }],
                        }
                    ]
                ]
            });
            $(document).on('click', '.btn-set', function (event) {
                var url = 'hf/qdgoods/set';
                var msg = 'H5加价';
                // var area = ['50%', '50%'];
                var options = {
                    shadeClose: false,
                    shade: [0.3, '#393D49'],
                    // area: area,
                    callback: function () {}
                };
                Fast.api.open(url, msg, options);
            });
            $(document).on('click', '.btn-priceset', function (event) {
                var url = 'hf/qdgoods/priceset';
                var msg = 'H5加价';
                // var area = ['50%', '50%'];
                var options = {
                    shadeClose: false,
                    shade: [0.3, '#393D49'],
                    // area: area,
                    callback: function () {}
                };
                Fast.api.open(url, msg, options);
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        sub: function () {
            Controller.api.bindevent();
        },
        set: function () {
            Controller.api.bindevent();
        },
        priceset: function () {
            Form.api.bindevent($("form[role=form]"));
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});